var GamePost = require('./gamePost/gamePost.model') 
var Comment = require('./comment/comment.model')
var User = require('./user/user.model')
var util = require ('util')
import mongoose from 'mongoose'
import config from '../../config'
var moment = require('moment');
var shortid = require('shortid');

// Database
mongoose.connect(config.mongo.uri, config.mongo.options)
mongoose.connection.on('error', function(err) {
    console.error(`MongoDB connection error: ${err}`)
    process.exit(-1); // eslint-disable-line no-process-exit
})



console.log('begins')
// var gamePost_1 = new GamePost({ _creator: '572f39270a8ac661160f31ac', title: 'gamePost_2', comments: [] });
// gamePost_1.save()

var currentdate = new Date(); 
var datetime = "Last Sync: " + currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/" 
                + currentdate.getFullYear() + " @ "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":" 
                + currentdate.getSeconds();
var datetime2 = moment(currentdate).format("YYYY-MM-DD-HH-mm-ss")

console.log(datetime2)


var slug_part = shortid.generate()
var full_slug_part = datetime2 + ':' + slug_part

var comment_1 = new Comment({
    _creator : '572f39270a8ac661160f31ac', 
    _post    : '57694c064c0518bd0fb82648',
    _parent  : '576a78fe1fd8d26d0ad6dceb',
    slug     : slug_part,
    full_slug: full_slug_part,   
    type     : 'gamepost', 
    title    : 'comment3_2',
    content  : 'cccc_2',
})

// comment_1.save(function (err, doc) {
//   if (err) return console.error(err);
//   console.log(util.inspect(doc, false, null))
// });





Comment.find({
  options: { sort: { full_slug: -1 } }
}).exec(function (err, docs) {
  if (err) return console.error(err);
  console.log(docs.length)
  return // Zoopa
})


Comment.find().exec(function (err, docs) {
  if (err) return console.error(err);
  console.log(docs)
  return // Zoopa
})

Comment.find()
        .sort({ full_slug: -1 })
        .select('slug')
        .exec(function (err, docs) {
              if (err) return console.error(err);
              console.log(docs)
              return // Zoopa
            })






// GamePost.findByIdAndUpdate(
//         '57694c064c0518bd0fb82648',
//         //{$push: {"_comments": "5767d9baee59f0640bbd1d6d"}},
//         {$push: {"_comments": "57694c064c0518bd0fb82649"}},        
//         {safe: true, upsert: true, new : true},
//         function(err, model) {
//             console.log(err);
//         }
//     );


// gamePost_1.save(function (err, post_doc) {
//   if (err) console.log(err);
  
//   comment_1._post = post_doc._id;
  
//   comment_1.save(function (err, c_doc) {
//     if (err) console.log(err);
//     post_doc._comments.push(c_doc._id)
//   });
// });



// gamePost_1.save(function (err , doc) {
//   if (err) return console.log(util.inspect(err, false, null))
//   else {
//   	console.log(util.inspect(doc, false, null))
//   	return
//   }
// })
